﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.IntegrationManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.IntegrationManagement.IntgrSyncRemoteVMs
{
    public partial class IntgrSyncRemoteListVM : BasePagedListVM<IntgrSyncRemote_View, IntgrSyncRemoteSearcher9>
    {
        
        protected override IEnumerable<IGridColumn<IntgrSyncRemote_View>> InitGridHeader()
        {
            return new List<GridColumn<IntgrSyncRemote_View>>{
                
                this.MakeGridHeader(x => x.IntgrSyncRemote_Wo).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_TransSnId).SetTitle(@Localizer["Page.流转号"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_ArchiveId).SetTitle(@Localizer["Page.产品出站"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_LineId).SetTitle(@Localizer["Page.产线号"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_ProductId).SetTitle(@Localizer["Page.产品号"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_OpId).SetTitle(@Localizer["Page.工位号"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_OpCode).SetTitle(@Localizer["Page.工位编码"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_ErpOpCode).SetTitle(@Localizer["Page.工厂工序编号"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_PassResult).SetTitle(@Localizer["Page.当前状态"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_Status).SetTitle(@Localizer["Page.同步状态"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_IsFirst).SetTitle(@Localizer["Page.首站"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_IsCompelted).SetTitle(@Localizer["Page.完工下线"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_SyncMethod).SetTitle(@Localizer["Page.同步方式"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_SyncCount).SetTitle(@Localizer["Page.执行次数"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_ErrMessage).SetTitle(@Localizer["Page.错误消息"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_CreatedTime).SetTitle(@Localizer["Page.数据生成时间"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_StartTime).SetTitle(@Localizer["Page.同步开始时间"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_EndTime).SetTitle(@Localizer["Page.同步结束时间"].Value),
                this.MakeGridHeader(x => x.IntgrSyncRemote_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<IntgrSyncRemote_View> GetSearchQuery()
        {
            var query = DC.Set<IntgrSyncRemote>()
                
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.TransSnId, x=>x.TransSnId)
                .CheckEqual(Searcher.ArchiveId, x=>x.ArchiveId)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.ErpOpCode, x=>x.ErpOpCode)
                .CheckEqual(Searcher.PassResult, x=>x.PassResult)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckEqual(Searcher.IsFirst, x=>x.IsFirst)
                .CheckEqual(Searcher.IsCompelted, x=>x.IsCompelted)
                .CheckContain(Searcher.SyncMethod, x=>x.SyncMethod)
                .CheckEqual(Searcher.SyncCount, x=>x.SyncCount)
                .CheckContain(Searcher.ErrMessage, x=>x.ErrMessage)
                .CheckBetween(Searcher.CreatedTime?.GetStartTime(), Searcher.CreatedTime?.GetEndTime(), x => x.CreatedTime, includeMax: false)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckBetween(Searcher.EndTime?.GetStartTime(), Searcher.EndTime?.GetEndTime(), x => x.EndTime, includeMax: false)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new IntgrSyncRemote_View
                {
				    ID = x.ID,
                    
                    IntgrSyncRemote_Wo = x.Wo,
                    IntgrSyncRemote_Sn = x.Sn,
                    IntgrSyncRemote_TransSnId = x.TransSnId,
                    IntgrSyncRemote_ArchiveId = x.ArchiveId,
                    IntgrSyncRemote_LineId = x.LineId,
                    IntgrSyncRemote_LineCode = x.LineCode,
                    IntgrSyncRemote_ProductId = x.ProductId,
                    IntgrSyncRemote_ProductName = x.ProductName,
                    IntgrSyncRemote_OpId = x.OpId,
                    IntgrSyncRemote_OpCode = x.OpCode,
                    IntgrSyncRemote_ErpOpCode = x.ErpOpCode,
                    IntgrSyncRemote_PassResult = x.PassResult,
                    IntgrSyncRemote_Status = x.Status,
                    IntgrSyncRemote_IsFirst = x.IsFirst,
                    IntgrSyncRemote_IsCompelted = x.IsCompelted,
                    IntgrSyncRemote_SyncMethod = x.SyncMethod,
                    IntgrSyncRemote_SyncCount = x.SyncCount,
                    IntgrSyncRemote_ErrMessage = x.ErrMessage,
                    IntgrSyncRemote_CreatedTime = x.CreatedTime,
                    IntgrSyncRemote_StartTime = x.StartTime,
                    IntgrSyncRemote_EndTime = x.EndTime,
                    IntgrSyncRemote_Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class IntgrSyncRemote_View: IntgrSyncRemote
    {
        
        public string IntgrSyncRemote_Wo { get; set; }
        public string IntgrSyncRemote_Sn { get; set; }
        public long? IntgrSyncRemote_TransSnId { get; set; }
        public long? IntgrSyncRemote_ArchiveId { get; set; }
        public long? IntgrSyncRemote_LineId { get; set; }
        public string IntgrSyncRemote_LineCode { get; set; }
        public long? IntgrSyncRemote_ProductId { get; set; }
        public string IntgrSyncRemote_ProductName { get; set; }
        public long? IntgrSyncRemote_OpId { get; set; }
        public string IntgrSyncRemote_OpCode { get; set; }
        public string IntgrSyncRemote_ErpOpCode { get; set; }
        public SnStatusEnum? IntgrSyncRemote_PassResult { get; set; }
        public RemoteSyncStatusEnum? IntgrSyncRemote_Status { get; set; }
        public bool? IntgrSyncRemote_IsFirst { get; set; }
        public bool? IntgrSyncRemote_IsCompelted { get; set; }
        public string IntgrSyncRemote_SyncMethod { get; set; }
        public int? IntgrSyncRemote_SyncCount { get; set; }
        public string IntgrSyncRemote_ErrMessage { get; set; }
        public DateTime? IntgrSyncRemote_CreatedTime { get; set; }
        public DateTime? IntgrSyncRemote_StartTime { get; set; }
        public DateTime? IntgrSyncRemote_EndTime { get; set; }
        public string IntgrSyncRemote_Remark { get; set; }

    }

}